package EventManager;

import java.util.LinkedList;

// most of these functions returned boolean, but exception handling is much cleaner 
public class Listener {
	private String m_name;
	private LinkedList<EventType> m_eventMonitor;

	public Listener() {
		m_eventMonitor = new LinkedList<EventType>();
	}

	// Adds an event to watch
	void addEventMonitor(EventType event) {
		m_eventMonitor.addFirst(event);
	}

	private static final String START_GAME_STRING = "EVENT_START_GAME";
	private static final String HANDLED_START_GAME_STRING = "YOU JUST HANDLED";
	private static final String HANDLED_END_GAME_STRING = "!!!!";

	// Handles the event
	boolean HandleEvent(EventType event) {
		// TODO implement
		String temp = START_GAME_STRING;

		if (!event.getName().equals(new String(temp + "1"))
				|| !event.getName().equals(new String(temp + "2"))
				|| !event.getName().equals(new String(temp + "3"))
				|| !event.getName().equals(new String(temp + "4"))
				|| !event.getName().equals(new String(temp + "5"))) {
			System.out.format(
					"%s %s %s\n", 
					HANDLED_START_GAME_STRING, 
					event.getName(), HANDLED_END_GAME_STRING);
			return true;
		}
		else
			return false;
	}

	// Deletes an event from being watched, maybe chance to exception
	// ElementDoesNotExist
	boolean deleteEventMonitor(EventType event) {
		if (m_eventMonitor.contains(event)) {
			m_eventMonitor.remove(event);
			return true;
		}
		else {
			return false;
		}
	}

	boolean deleteEventMonitor(String eventName) {
		// TODO implement
		for (EventType e : m_eventMonitor) {
			if (e.getName().equals(eventName)) {
				m_eventMonitor.remove(e);
				return true;
			}
		}
		return false;

	}

	// returns true if it has that event, else no
	boolean SearchEventMonitor(EventType event) {
		return m_eventMonitor.contains(event);
	}

	String getName() {
		return m_name;
	}

	void setName(String name) {
		m_name = name;
	}

}
